// @ts-ignore
import type { PaginationProps } from 'antd/lib/pagination';
import type { ProColumns, ProTableProps } from '@ant-design/pro-components';
import type { BaseServices, Bean } from './base';
import type { SearchProps } from 'antd/lib/input';
import type { ColProps } from 'antd/lib/col';

/*
 * List page start
 */

export interface FormItemLayout {
  labelCol?: {
    span: number;
  };
  wrapperCol?: {
    span: number;
  };
}

export type Style = React.CSSProperties;

export type Props = Bean;

export type ColumnsMap<TItemDat extends Bean = Bean> = Record<
  string,
  ProColumns<TItemDat, string>
>;

export interface CrudPageConfig {
  /*  实体对象主键 例如 id */
  primaryKey: 'id' | string;
  /* 是否有搜索 */
  showFilter: boolean;
  /* 是否显示 分页  */
  showPagination: boolean;
  /* 搜索字段列表  字段属性集合 */
  filterKeys: string[];
  /* 表格字段列表  字段属性集合 */
  columnsKeys: string[];
  /* 编辑表格列表  字段属性集合 */
  detailFormKeys: string[];
  columns: ProColumns[];
  filterColumns: ProColumns<Bean>[];
  addFormColumns: ProColumns<Bean>[];
  editFormColumns: ProColumns<Bean>[];
  showOpColumn: boolean;
  /* 表格 column 公共属性 */
  columnPublicProps: ProColumns<Bean>;
  tablePublicProps: ProTableProps<Bean, Bean>;
  paginationPublicProps: PaginationProps;
  columnsMap: ColumnsMap;
  services: BaseServices;
  /* 展示简介搜索 [只有关键字搜索] */
  showConciseSearch: boolean;
  /* 简介搜索关键字 对应于的字段名 */
  conciseSearchFieldKey: string;
  /* 简介搜索关键字 输入框属性 */
  conciseSearchProps: SearchProps | false;
  /* 编辑数据时加载详情 */
  loadDetailsForModify: boolean;
  detailFormLayout: Record<string, ColProps>;
  PageContainer: any;
  // [key: string]: any;
}

/*
 * @type P: Type of payload
 * @type C: Type of callback
 */
export type Dispatch = <P = any, C = (payload: P) => void>(action: {
  type: string;
  payload?: P;
  callback?: C;
  [key: string]: any;
}) => any;

export interface CrudPageProps<T = Bean> {
  list: T[];
  pageInfo: PaginationProps;
  commonLoading: boolean;
  [key: string]: any;
}

export type PartialCrudPageProps = Partial<CrudPageProps>;
export interface CrudPageState {
  selectedRecord: Bean;
  [key: string]: any;
}

export interface CrudPageDetailProps {
  type: 'add' | 'modify' | 'detail';
  wrapperChildrenStyle: React.CSSProperties;
  onSubmit: (data: any, otherProps: any) => any;
  onLoadDetail: (data: any, callback: (data: any) => void) => any;
  loading: boolean;
  isLoadDetail: boolean;
  record: Bean;
  topTitle: string | React.ReactNode;
  title?: string | React.ReactNode;
  continueSave: boolean;
  width: number | string | '100%';
  displayType: 'displayTypeDrawer' | 'displayTypeModal';
  match?: any;
  style: React.CSSProperties;
  [key: string]: any;
}

export interface CrudPageDetailState {
  visible: boolean;
}

/*
 * List page end
 */

export type ValueEnum = Record<
  string,
  | React.ReactNode
  | {
      text: React.ReactNode | string;
      status?: 'Success' | 'Error' | 'Processing' | 'Warning' | 'Default';
    }
>;
